/**
 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software 
 * and associated documentation files (the "Software"), to deal in the Software without restriction, 
 * including without limitation the rights to use, copy, modify, merge, publish, distribute, 
 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all copies or 
 * substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT 
 * NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 * 
 * @license     http://www.opensource.org/licenses/mit-license.php MIT License
 * @copyright   Copyright (c) 2009 James Rodenkirch, Active Binary
 * @author      James Rodenkirch <james@activebinary.com>
 * @package     ActiveText
 * @version     $Rev: 12 $
 */

/* ============================================================================================== */

/**
 * Configuration: Path to the php script that generates dynamic text images 
 */
var php_script = '/ActiveText/textimage.php';

/* ---------------------------------------------------------------------------------------------- */ 

/**
 * ActiveText for MooTools
 * This class swaps textual content of html elements for image versions
 */
var ActiveText = Class.create({

  /**
   * Class constructor
   */
  initialize: function(types){
	
	// initialize array to hold preloaded images
	preload = new Array();
  
    // loop through json object passed and build a list of dom elements to process
    types.each(function(obj, idx){
    
      // loop through each dom element and process
      $$(obj.selectors).each(function(el, val){
    	  
    	// preload the image
    	pic = new Image(); 
    	pic.src = php_script+"?preset="+obj.preset+"&text="+el.innerHTML; 
      
        // update the element to have an img instead of text
        el.innerHTML = "<img src='"+php_script+"?preset="+obj.preset+"&text="+el.innerHTML+"' alt='"+el.innerHTML+"' title='"+el.innerHTML+"'>";
      });
    });
  }
});
